Kotlin uses the data type Unit
to represent the absence of a value in a function or an expression. It corresponds to the type
void
in Java or unknown
in JavaScript. While Void
is available in Kotlin, it is a Java platform type and not
equivalent to Java void
but java.lang.Void
.
Use Unit
instead of Void
because it represents the absence of a value in Kotlin.
What is the potential impact?
Wrong logic
Void
is not equivalent to Java void
but java.lang.Void
.
Unnecessary platform dependency
Void
is a platform type available only in the Java Runtime Environment.